package com.weilai.dao;

import com.weilai.domain.ReportInfo;
import com.weilai.domain.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserDao {
    //查询所有用户
    @Select("SELECT * FROM users")
    public List<User> getAllUsers();

    //按id查询用户
    @Select("SELECT * FROM users where id=#{id}")
    public User getById(int id);

    //按id查询用户
    @Select("SELECT * FROM users where username=#{username}")
    public User getByUsername(String username);

    //用户注册
    @Insert("INSERT INTO users (username, email, password, gender, role, status, created_at, updated_at, follower_count, subscription)\n" +
            "VALUES (#{username},#{email},#{password},'女','user','正常',#{createdAt},#{updatedAt},0,0);")
    public void insertUser(User user);
    //用户注册
    @Insert("INSERT INTO users (username, email, password, gender, role, status, follower_count, subscription)\n" +
            "VALUES (#{username},#{email},#{password},'女','user','正常',0,0);")
    public void insertUser2(User user);

    //修改用户信息
    @Update("UPDATE users " +
            "SET username = #{username}, " +
            "    email = #{email}, " +
            "    password = #{password}, " +
            "    gender = #{gender}, " +
            "    role = #{role}, " +
            "    avatar = #{avatar}, " +
            "    bio = #{bio}, " +
            "    created_at = #{createdAt}, " +
            "    updated_at = #{updatedAt}, " +
            "    follower_count = #{followerCount}, " +
            "    subscription = #{subscription}, " +
            "    short_bio = #{shortBio}, " +
            "    location = #{location}, " +
            "    industry = #{industry} " +
            "WHERE id = #{id}")
   public void updateUser(User user);


    // 按 id 删除用户信息
    @Delete("DELETE FROM users WHERE id = #{id}")
    int deleteUserById(int id);

    //按邮箱查找用户
    @Select("SELECT * FROM users where email=#{email}")
    public User getByEmail(String email);
    //查询用户名是否存在
    @Select("SELECT * FROM users WHERE username=#{username}")
    public User selectUserName(String username);

//    //举报他人
//    @Insert("INSERT INTO report_info (post_id, reporter_id, report_type, report_reason)\n" +
//            "VALUES (#{postId}, #{reporterId}, #{reportType}, #{reportReason}); ")
//    public void reportOthers(ReportInfo reportInfo);

    //根据用户名关键字查询
    @Select("select * from users where username like concat('%',#{Keywords},'%')")
    List<User> selectByKeywords(String Keywords);


}
